<template>
  <div id="rankdetail">
    <div class="detail">
      <div class="left"><img :src="detail.coverImgUrl" alt="" /></div>
      <div class="right">
        <div class="title flex_start">
          <p class="tag flex_center">歌单</p>
          <p class="name">{{ detail.name }}</p>
        </div>
        <div class="update-time flex_start">
          <div class="icon"><img src="./images/iconlogo.png" alt="" /></div>
          <p class="wy">网易云音乐</p>
          <p>最近更新：</p>
          <p class="time">{{ myMonth }}月{{ myDates }}日</p>
        </div>
        <div class="btns flex_start">
          <div class="play-all flex_center">
            <div class="icon"><img src="./images/play (1).png" alt="" /></div>
            <p @click="addList">播放全部</p>
            <p class="add">+</p>
          </div>
          <div class="collection flex_center">
            <div class="icon"><img src="./images/collection.png" alt="" /></div>
            <p>收藏({{Math.round(detail.subscribedCount/10000)}}万)</p>
          </div>
          <div class="share flex_center">
            <div class="icon"><img src="./images/share.png" alt="" /></div>
            <p>分享</p>
          </div>
          <div class="dowanload-all flex_center">
            <div class="icon"><img src="./images/download.png" alt="" /></div>
            <p>下载全部</p>
          </div>
        </div>
        <div class="playNum flex_start">
            <p>歌曲:{{list.length}}</p>
            <p>播放：{{detail.playCount>10000?Math.floor(detail.playCount/10000)+"万":detail.playCount}}</p>
        </div>
        <div class="dec">
           简介：{{detail.description}}
        </div>
      </div>
    </div>
    <div class="tab flex_space_btween">
        <div class="left flex_start">
            <router-link to="" tag="p" class="song-list active">歌曲列表</router-link>
            
            <p class="comment">评论()</p>
            <p class="collector">收藏者</p>
        </div>
        <div class="right flex_space_btween">
            <input type="text" placeholder="搜索歌单音乐">
            <div class="icon"><img src="./images/search.png" alt=""></div>
        </div>
    </div>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: "rankdetail",
  data() {
    return {
      detail: this.$route.query.detail,
      list: [],
      myMonth: "00",
      myDates: "00",
      timestamp: this.$route.query.detail.updateTime,
    };
  },
  methods: {
    addList(){
       this.$store.state.playMusicList.push(...this.list)
       let obj = {};
          this.$store.state.playMusicList = this.$store.state.playMusicList.reduce(
            function (item, next) {
              obj[next.id] ? "" : (obj[next.id] = true && item.push(next));
              return item;
            },
            []
          );
        console.log("添加歌单成功",this.$store.state.playMusicList);
    }
  },
  created() {
    //时间戳转换为时间
    let date = new Date(this.timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
    let M = date.getMonth() + 1;
    let D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
    this.myMonth = M;
    this.myDates = D;

//根据 url id得到数据
     this.axios({
      method: "get",
      withCredentials: true,
      url: "https://music.hzbiz.net/playlist/detail?timetamp="+new Date().getTime(),
      params: {
        id: this.$route.query.id,
      },
    }).then((res) => {
      console.log("先", res.data.playlist);
     this.detail = res.data.playlist;
     this.list = res.data.playlist.tracks;
    });
  },
};
</script>

<style scoped>
.detail {
  margin: 28px;
  display: flex;
  justify-content: flex-start;
}
.detail .left {
  width: 188px;
  height: 188px;
  border-radius: 5px;
  overflow: hidden;
  margin-right: 20px;
}
.detail .right {
  width: 80%;
}
.detail .right .title {
  margin-top: 3px;
  margin-bottom: 5px;
}
.detail .right .title p.tag {
  width: 35px;
  height: 20px;
  color: #ec4141;
  border: 1px solid #ec4141;
  border-radius: 3px;
}
.detail .right .title p.name {
  font-weight: bold;
  font-size: 25px;
  margin-left: 10px;
}
.detail .right .update-time .icon {
  width: 29px;
  height: 29px;
  overflow: hidden;
}
.detail .right .update-time p {
  color: #676767;
}
.detail .right .update-time p.wy {
  color: #507daf;
  margin: 0 5px;
}
.btns{margin-top: 15px;}
.btns>div{
    padding: 0px 18px;
    font-size: 16px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    margin-right: 10px;
    cursor: pointer;
    height: 32px;
}
.btns>div:hover{background-color: #f5f5f5;}
.btns .play-all{
    color: #ffffff;
    background-color: #EC4141;
}
.btns .play-all:hover{background-color: brown;}
.btns .add{
    font-size: 25px;
    margin-left: 15px;
}
.btns .icon{
    width: 20px;
    height: 20px;
    overflow: hidden;
    margin-right: 5px;
}
.playNum{
    margin-top: 20px;
}
.playNum p{
    margin-right: 15px;
}
.dec{
    margin-top: 5px;
}
.tab{margin: 0 28px;}
.tab .left .active{
    font-weight:bold;
    border-bottom: 3px solid #EC4141;
}
.tab .left p{margin-right: 25px;line-height: 25px;}
.tab .right{
    width: 250px;
    height: 26px;
    border-radius: 13px;
    background-color: #f5f5f5;
}
.tab .right input{
    background-color: #f5f5f5;
    margin-left: 15px;
}
.tab .right .icon{
    width: 16px;
    height: 16px;
    overflow: hidden;
    margin-right: 10px;
}
</style>